package com.java.Jdbc;

import java.util.Scanner;
import java.sql.*;

public class LoginDemo1 {
    public static final String url = "jdbc:mysql://localhost:3306/aigou?serverTimezone=GMT&useUnicode=true&characterEncoding=UTF-8&useSSL=false";
    public static final String USERNAME = "root";
    public static final String PASSWORD = "root";
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String username = scanner.nextLine();
        System.out.println("请输入密码：");
        String password = scanner.nextLine();
        try(Connection connection = DriverManager.getConnection(url,USERNAME,PASSWORD)){
            PreparedStatement preparedStatement = connection.prepareStatement
                    ("select * from t_user where username=? and password = ?");
            preparedStatement.setObject(1,username);
            preparedStatement.setObject(2,password);
            ResultSet resultSet = preparedStatement.executeQuery();
            if(resultSet.next()){
                System.out.println("登录成功！");
            }else{
                System.out.println("登录失败！");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
